/*
 * 2021.03.27-Code rectification and function enhancement.
 *            Huawei Device Co., Ltd. <mobile@huawei.com>
 */

#ifndef __UISCROLLBAR_H__
#define __UISCROLLBAR_H__

#pragma once

namespace DuiLib {
class UILIB_API CScrollBarUI : public CControlUI, public IMessageFilterUI {
    DECLARE_DUICONTROL(CScrollBarUI)
public:
    CScrollBarUI();
    ~CScrollBarUI();

    LPCTSTR GetClass() const;
    LPVOID GetInterface(LPCTSTR pstrName);

    LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool &bHandled);

    CContainerUI *GetOwner() const;
    void SetOwner(CContainerUI *pOwner);

    void SetVisible(bool bVisible = true) override;
    void SetEnabled(bool bEnable = true) override;
    void SetFocus() override;

    bool IsHorizontal();
    void SetHorizontal(bool bHorizontal = true);
    int GetScrollRange() const;
    void SetScrollRange(int nRange);
    int GetScrollPos() const;
    void SetScrollPos(int nPos);
    int GetLineSize() const;
    void SetLineSize(int nSize);

    bool GetShowButton1();
    void SetShowButton1(bool bShow);
    LPCTSTR GetButton1NormalImage();
    void SetButton1NormalImage(LPCTSTR pStrImage);
    LPCTSTR GetButton1HotImage();
    void SetButton1HotImage(LPCTSTR pStrImage);
    LPCTSTR GetButton1PushedImage();
    void SetButton1PushedImage(LPCTSTR pStrImage);
    LPCTSTR GetButton1DisabledImage();
    void SetButton1DisabledImage(LPCTSTR pStrImage);

    bool GetShowButton2();
    void SetShowButton2(bool bShow);
    LPCTSTR GetButton2NormalImage();
    void SetButton2NormalImage(LPCTSTR pStrImage);
    LPCTSTR GetButton2HotImage();
    void SetButton2HotImage(LPCTSTR pStrImage);
    LPCTSTR GetButton2PushedImage();
    void SetButton2PushedImage(LPCTSTR pStrImage);
    LPCTSTR GetButton2DisabledImage();
    void SetButton2DisabledImage(LPCTSTR pStrImage);

    LPCTSTR GetThumbNormalImage();
    void SetThumbNormalImage(LPCTSTR pStrImage);
    LPCTSTR GetThumbHotImage();
    void SetThumbHotImage(LPCTSTR pStrImage);
    LPCTSTR GetThumbPushedImage();
    void SetThumbPushedImage(LPCTSTR pStrImage);
    LPCTSTR GetThumbDisabledImage();
    void SetThumbDisabledImage(LPCTSTR pStrImage);

    LPCTSTR GetRailNormalImage();
    void SetRailNormalImage(LPCTSTR pStrImage);
    LPCTSTR GetRailHotImage();
    void SetRailHotImage(LPCTSTR pStrImage);
    LPCTSTR GetRailPushedImage();
    void SetRailPushedImage(LPCTSTR pStrImage);
    LPCTSTR GetRailDisabledImage();
    void SetRailDisabledImage(LPCTSTR pStrImage);

    LPCTSTR GetBkNormalImage();
    void SetBkNormalImage(LPCTSTR pStrImage);
    LPCTSTR GetBkHotImage();
    void SetBkHotImage(LPCTSTR pStrImage);
    LPCTSTR GetBkPushedImage();
    void SetBkPushedImage(LPCTSTR pStrImage);
    LPCTSTR GetBkDisabledImage();
    void SetBkDisabledImage(LPCTSTR pStrImage);

    void SetPos(RECT rc, bool bNeedInvalidate = true);
    void DoEvent(TEventUI &event) override;
    void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);

    void DoPaint(HDC hDC, const RECT &rcPaint);
    void DoInit() override;

    void PaintBk(HDC hDC);
    void PaintButton1(HDC hDC);
    void PaintButton2(HDC hDC);
    void PaintThumb(HDC hDC);
    void PaintRail(HDC hDC);
    void ButtonDownEvent(TEventUI &event);
    void ButtonElseEvent(TEventUI &event);
    bool CheckMouseSatus(TEventUI &event);
    void SetScrollBarWidth(int nRange);
    void SetMinThumbWidth(int minThumbWidth);

protected:
    enum {
        DEFAULT_SCROLLBAR_SIZE = 16,
        DEFAULT_TIMERID = 10,
    };

    bool m_bHorizontal;
    int m_nRange;
    int m_nScrollPos;
    int m_nLineSize;
    POINT ptLastMouse;
    int m_nLastScrollPos;
    int m_nLastScrollOffset;
    int m_nScrollRepeatDelay;

    CDuiString m_sBkNormalImage;
    CDuiString m_sBkHotImage;
    CDuiString m_sBkPushedImage;
    CDuiString m_sBkDisabledImage;

    bool m_bShowButton1;
    RECT m_rcButton1;
    UINT m_uButton1State;
    CDuiString m_sButton1NormalImage;
    CDuiString m_sButton1HotImage;
    CDuiString m_sButton1PushedImage;
    CDuiString m_sButton1DisabledImage;

    bool m_bShowButton2;
    RECT m_rcButton2;
    UINT m_uButton2State;
    CDuiString m_sButton2NormalImage;
    CDuiString m_sButton2HotImage;
    CDuiString m_sButton2PushedImage;
    CDuiString m_sButton2DisabledImage;

    RECT m_rcThumb;
    UINT m_uThumbState;
    CDuiString m_sThumbNormalImage;
    CDuiString m_sThumbHotImage;
    CDuiString m_sThumbPushedImage;
    CDuiString m_sThumbDisabledImage;

    CDuiString m_sRailNormalImage;
    CDuiString m_sRailHotImage;
    CDuiString m_sRailPushedImage;
    CDuiString m_sRailDisabledImage;

    CDuiString m_sImageModify;

    bool m_bCapture = false;
    int m_minThumbWidth = 15;

public:
    CContainerUI *m_pOwner;
};
}

#endif // __UISCROLLBAR_H__